home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / system-config-printer / gtk_label_autowrap.py < prev    next >
Encoding:
Python Source  |  2009-05-05  |  1.6 KB  |  49 lines

  1. # utils.py
  2. #
  3. # Copyright (c) 2004 Thomas Woerner <twoerner@redhat.com>
  4. # Copyright (c) 2006 Florian Festi <ffesti@redhat.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. import gtk
  22. from pango import SCALE
  23.  
  24. ### set autowrapping for all labels in this widget tree
  25. def set_autowrap(widget):
  26.     if isinstance(widget, gtk.Container):
  27.         children = widget.get_children()
  28.         for i in xrange(len(children)):
  29.             set_autowrap(children[i])
  30.     elif isinstance(widget, gtk.Label) and widget.get_line_wrap():
  31.         widget.connect_after("size-allocate", label_size_allocate)
  32.  
  33. ### set wrap width to the pango.Layout of the labels ###
  34. def label_size_allocate(widget, allocation):
  35.     layout = widget.get_layout()
  36.  
  37.     lw_old, lh_old = layout.get_size()
  38.     # fixed width labels
  39.     if lw_old/SCALE == allocation.width:
  40.         return
  41.     layout.set_width(allocation.width * SCALE)
  42.  
  43.     lw, lh = layout.get_size()
  44.  
  45.     if lh_old != lh:
  46.         widget.set_size_request(-1, lh/SCALE)
  47.         
  48.     return
  49.